{% extends './blog_base.html' %}

{% block title %} 首页 {% end %}

{% block body %}
<div class="flex-fill">
    <div class="header header-bg" style="background-image: url(/static/photos/anders-jilden-307322-1500.jpg);">
        <a class="header-brand" href="/">
            {{author.name}}-BLOG
        </a>
        <br> 
        <span class="header-brand-span">各位，嗨起来吧！！！！</span>
    </div>
    <div class="my-3 my-md-5">
        <div class="container">
            <div class="row row-cards">
                <!-- 文章列表 -->
                <div class="col-lg-9">
                {% if len(post_list)==0 %}
                暂无数据~
                {% end %}
                {% for post in post_list %}
                    <div class="card card-aside">
                        <div class="card-body d-flex flex-column">
                            <h4><a href="/blog/{{post.id}}">{{post.title}}</a></h4>
                            <div class="text-muted">{{post.excerpt}}...</div>
                            <div class="d-flex align-items-center pt-5 mt-auto">
                                <div class="avatar avatar-md mr-3"
                                    style="background-image: url(/static/faces/male/33.jpg)">
                                </div>
                                <div>
                                    <small class="d-block ">{{post.author_name}} · {{post.views}} 人次阅读 · {{post.category_name}}</small>
                                    <small class="d-block ">{{post.create_time}}</small>
                                </div>
                                <div class=" tags" style="margin-left: 3rem; margin-top: 1rem;">
                                    {% for name in post.tag_names %}
                                        <span class="tag">{{name}}</span>
                                    {% end %}
                                </div>
                            </div>
                        </div>
                    </div>
                {% end %}
                </div>
                <div class="col-lg-3">
                    <!-- 搜索框 -->
                    <div class="card">
                        <div class="input-group">
                            <input type="text" class="form-control" name="search" placeholder="Search for..." {% if search %} value="{{search}}" {% end %}>
                            <span class="input-group-append">
                              <button class="btn btn-primary" type="button" onclick="search()">Go!</button>
                            </span>
                            <a href="" id="search"></a>
                          </div>
                    </div>
                    <!-- 博主信息 -->
                    <div class="card card-profile">
                        <div class="card-header" style="background-image: url(/static/photos/eberhard-grossgasteiger-311213-500.jpg);"></div>
                        <div class="card-body text-center">
                          <img class="card-profile-img" src="/static/faces/male/33.jpg">
                          <h3 class="mb-3">{{author.name}}</h3>
                          <p class="mb-4">
                            {{author.bio}}
                          </p>
                          <p class="mb-4">
                            Email：<a href="#" target="_blank">{{author.email}}</a>
                          </p>
                          <button class="btn btn-outline-primary btn-sm">
                            <span class="fa fa-hand-o-right"></span> 点赞
                          </button>
                        </div>
                    </div>
                    <!-- 分类 -->
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">分类</h3>
                        </div>
                        <div class="card-body">
                            <div class="list-group list-group-transparent mb-0">
                                <a href="/" class="list-group-item list-group-item-action 
                                    {% if cate_id == 0 %} active {% end %}">
                                    <span class="float-right"><span class="badge badge-primary">{{post_count}}</span></span>
                                    <span class="icon mr-3">
                                        <i class="fe fe-align-left"></i>
                                    </span>
                                    全部
                                </a>
                                {% for cate in category_list %}
                                    <a href="/?cate_id={{cate.id}}" class="list-group-item list-group-item-action {% if cate_id==cate.id %} active {% end %}">
                                        <span class="float-right"><span class="badge badge-primary">{{cate.post_count}}</span></span>
                                        <span class="icon mr-3">
                                            <i class="fe fe-chevron-right"></i>
                                        </span>
                                        {{cate.name}}
                                    </a>
                                {% end %}
                            </div>
                        </div>
                    </div>
                    <!-- 标签云 -->
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">标签云</h3>
                        </div>
                        <div class="card-body">
                            <div class="selectgroup selectgroup-pills">
                                {% if len(tag_list)==0 %}
                                暂无数据~
                                {% end %}
                                {% for tag in tag_list %}
                                    <label class="selectgroup-item">
                                        <input type="radio" name="tags" value="{{tag.id}}" class="selectgroup-input" onclick="selectTag('{{tag.id}}')"
                                        {% if tag_id == tag.id  %} checked="" {% end %}>
                                        <span class="selectgroup-button">{{tag.name}}</span>
                                        <a href="/?tag_id={{tag.id}}" id="tag_{{tag.id}}"></a>
                                    </label>
                                {% end %}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function search(){
        let inputSearch = $("input[name=search]").val()
        if (inputSearch != ""){
            console.log(inputSearch)
            $("#search").attr("href", `/?search=${inputSearch}`)
            $("#search")[0].click()
        }
    }

    function selectTag(tag_id){
        console.log(tag_id)
        $("#tag_"+tag_id)[0].click()
    }
</script>
{% end %}